﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;

namespace uTorrentSL.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class HomeViewModel : ViewModelBase
    {
        public RelayCommand ConnectCommand { get; set; }




        public bool ConnectEnable { get; set; }

        /// <summary>
        /// Initializes a new instance of the HomeViewModel class.
        /// </summary>
        public HomeViewModel()
        {
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real": Connect to service, etc...
            ////}
            ConnectEnable = true;

            Messenger.Default.Register<string>(this, "LoadStarted", LoadStarted);
            Messenger.Default.Register<string>(this, "LoadComplete", LoadComplete);

            ConnectCommand = new RelayCommand(() =>
            {
                //ViewModel.ViewModelLocator.Password = Pass;
                //ViewModel.ViewModelLocator.Username = User;
                //ViewModel.ViewModelLocator.HostPort = Host;
                ViewModel.ViewModelLocator.Settings.Save();
                ViewModel.ViewModelLocator.DataService = ViewModel.ViewModelLocator.GetDataService();
                
            });
        }


        public void LoadStarted(string s)
        {
            ConnectEnable = false;
        }

        public void LoadComplete(string s)
        {
            ConnectEnable = true;
        }

        ////public override void Cleanup()
        ////{
        ////    // Clean own resources if needed

        ////    base.Cleanup();
        ////}
    }
}